<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('库存转移管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">创建人</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="cjry" name="cjry" placeholder="创建人"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">提起人</label>
                        <input type="text" class="layui-input" id="tqrxm" name="tqrxm" placeholder="提起人"/>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">移动状态</label>
                        <select name="ydzt" lay-filter="aihao">
                            <option value=""></option>
                            <option value="0">未处理</option>
                            <option value="1">已处理</option>
                            <option value="2">作废</option>
                        </select>
                    </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">创建时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="stime" id="stime"
                                       placeholder="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal" >重置</button>
                        </button>
                    </div>
                </form>
              <!--  <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>-->
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
        <div id="bjEdit" style="display: none">
                <form class="layui-form layui-form-pane" id="formEdit">
                    <div class="layui-inline"  style="left: 20px;">
                        <label>提起人</label>
                        <div class="layui-input-inline">
                            <input type="text"autocomplete="off" class="layui-input"  id="tid" name="tqrxm" placeholder="提起人"/>
                        </div>
                    </div>
                    <div class="layui-inline"  style="left: 20px;">
                        <label>移动原因</label>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" class="layui-input"  id="yid" name="ydyy" placeholder="移动原因"/>
                        </div>
                    </div>
                </form>
        </div>
    </div>
</div>

</body>


<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script th:inline="javascript">
    $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
    });
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {


        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    console.log("点查询了");
                    zzpUtils.refreshTable("#table");
                },
                /*新增*/
                addEvent: function (data) {
                    add();
                },
                /*编辑*/
                editEvent: function (data) {
                    if (data.row != undefined) {
                        upDialog(data);
                    }
                },
                /*确认收货*/
                confirmEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id);
                        startDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            startDialog(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*明细*/
                getEvent: function (data) {
                    console.log(data);
                    if (data.row != undefined) {
                        if(data.row.ydzt=='0'){//未处理
                            btnDialog(data.row.id);
                        }else{
                            editDialog(data.row.id);
                        }
                    }
                },
                /*删除*/
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        delDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            delDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*导出*/
                exportEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        /*
                        * 以下是将ids和对象拼接在一起
                        * */
                        var str = zzpUtils.getFormJson($("#searchForm"));
                        var object2 = Object.assign({ids: ids}, str);
                        /*将条件查询和ids传到后台*/
                        zzpUtils.outputXslx({
                            url: "/wmsstockmove/exportWmsStockMove",
                            data: JSON.stringify(object2)
                        });
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                        }
                        /*
                         * 以下是将ids和对象拼接在一起
                         * */
                        var str = zzpUtils.getFormJson($("#searchForm"));
                        var object2 = Object.assign({ids: arr}, str);
                        /*将条件查询和ids传到后台*/
                        zzpUtils.outputXslx({
                            url: "/wmsstockmove/exportWmsStockMove",
                            data: JSON.stringify(object2)
                        });
                    }
                }
            }
        });
        //初始化
        zzpUtils.webSocket.init();

        //新增
        function add() {
            zzpUtils.dialog({
                title: "新增库存移动",
                type: 2,
                content: "/kczy/addKczy",
                area: ['95%', '95%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        //查看明细
        function editDialog(id) {
            zzpUtils.dialog({
                title: "查看明细",

                type: 2,
                content: "/kczy/getFindInfo?id=" + id,
                area: ['90%', '90%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
        //未处理查看明细
        function btnDialog(id){
            zzpUtils.dialog({
                title: "查看明细",
                type: 2,
                content: "/kczy/getMingXiInfo?id=" + id,
                area: ['90%', '90%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        //确认收货
        function startDialog(ids) {

            zzpUtils.confirm("您将进行确认库存转移的操作", function (index) {
                zzpUtils.action({
                    url: "/wmsstockmove/saveConfirm",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        setTimeout(function () {
                            if(data.type=='success'){
                                layer.msg(data.title);
                            }else{
                                layer.msg(data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }

        //删除
        function delDialog(ids) {

            zzpUtils.confirm("您将删除选择的数据", function (index) {
                zzpUtils.action({
                    url: "/wmsstockmove/delete",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        setTimeout(function () {
                            if(data.type=='success'){
                                layer.msg(data.title);
                            }else{
                                layer.msg(data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }

        //编辑
        function upDialog(data) {
            layer.open({
                type: 1,
                title: '编辑库存移动',
                area: ['40%', '55%'],
                content: $("#bjEdit"),//支持获取DOM元素
                btn: ['保存', '取消'], //按钮
                success:function(index){
                     $("#tid").val(data.row.tqrxm);
                     $("#yid").val(data.row.ydyy);
                },
                yes: function (index2) {
                    var tid = $("#tid").val();
                    var yid = $("#yid").val();
                    zzpUtils.confirm("您确认要编辑吗", function (index) {
                        zzpUtils.action({
                            url: "/wmsstockmove/baseUpdateByPrimaryKey",
                            data: JSON.stringify({id: data.row.id, tqrxm: tid, ydyy: yid}),
                            success: function (data) {
                                setTimeout(function () {
                                    layer.close(index2);
                                    layer.close(index); //再执行关闭
                                    if(data.type=='success'){
                                        layer.msg(data.title);
                                    }else{
                                        layer.msg(data.message);
                                    }
                                }, 500);
                                zzpUtils.refreshTable("#table");
                            }, error: function (xhr, textStatus) {
                                console.log(textStatus);
                                console.log(xhr)
                            }
                        })
                    })
                },
                btn2: function (index) {
                    layer.close(index);
                }
            });

        }

        laydate.render({
            elem: '#stime'
            , theme: '#20a0ff'
            , range: '~'//练起来
        })
        laydate.render({
            elem: '#etime'
            , theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            //functions: functions.tableBtn,
            pagination: true,
            url: '/wmsstockmove/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'cjsj',
                title: '创建时间',
                width: 130
            }, {
                field: 'tqrxm',
                title: '提起人',
                width: 150
            }, {
                field: 'cjry',
                title: '创建人',
                width: 120
            }, {
                field: 'qrry',
                title: '确认人',
                width: 130
            }, {
                field: 'ydyy',
                title: '移动原因'
            }, {
                field: 'qrsj',
                title: '确认时间'
            }, {
                field: 'show_ydzt',
                title: '移动状态',
                width: 130
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter
        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.ydzt == '0') {
                    button += btn;
                } else if (row.ydzt == '1') {
                    if (functions.tableBtn[i].name == '导出' || functions.tableBtn[i].name == '明细') {
                        button += btn;
                    }
                }
            }
            button += '</span>'
                + '</div>';
            return button;
        }


        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var button = '', buttons1 = '', buttons2 = '';
            var buttons = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var btn = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (item.event === 'getEvent' || item.event === 'exportEvent') {
                    buttons1 += '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                } else {
                    if (row.ydzt == '0') {
                        if (functions.tableBtn[i].name == '编辑' || functions.tableBtn[i].name == '删除'
                            || functions.tableBtn[i].name == '确认' ) {
                            buttons2 += btn;
                        }
                    }

                }
            }
            button += buttons1;
            // button += buttons;
            button += buttons2;
            button += '</span>'
                + '</div>';
            return button;
        }


        //查询
       /* $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })*/

    });


</script>
</html>